#!/bin/awk -f
# Synopsis: tmsym Tgroup.sel.erep
# file Tgroup.tm has to be in the same dir
BEGIN{
  split(ARGV[1],a,".");
  fn=a[1]".tm";
  i=0; while(getline<fn){ 
    if(i==0)mdim=$3; # line: dim = mdim
    if(i>0){
      for(j=1;j<=mdim;j++)if(i!=j){
	m[i,j]=$j;
	if($j>pmax){pmax=$j}
      };
    }
    i++;
  }
}
$0!~/^\#/{
  ni++;
  sub(/\#.*$/,"");
  na[ni]=split($0,a);
  for(i=1;i<=na[ni];i++){po[a[i]]=ni};
}
END{
  mf=1; if(ni>9){mf=2};if(ni>99){mf=3};
  for(j=1;j<=mdim;j++){
    for(k=1;k<=mdim;k++){
      if(j!=k){
	printf("%"mf"i ",po[m[j,k]]);
      }else{
	printf("%"mf"s ","-");
      }
    }
    printf("\n");
  }
}
